import {ref} from 'vue';
import { defineStore } from 'pinia';

export const useAuthStore = defineStore(
    "auth",
     () => {
        const isAdmin = ref(false);
        const authMenu:any = ref([]);
        const menuIds:any = ref([])
        const menuIndex:any = ref('')
        const isCollapse:any = ref(false);

        // 更新isAdmin
        const updateAdmin = (flag: boolean) => {
            isAdmin.value = flag;
        };

        // 更新authMenu
        const updateMenu = (list: any) => {
            authMenu.value = list;
        };
    
        // 更新menuIds
        const updateIds = (ids: any) => {
            menuIds.value = ids;
        };

        // 更新menuIdex
        const updateIndex = (index: string) => {
            menuIndex.value = index;
        };

        // 更新isCollapse
        const updateCollapse = (bool: boolean) => {
            isCollapse.value = bool;
        };

        return { isAdmin, authMenu, menuIds, menuIndex, isCollapse, updateAdmin, updateMenu, updateIds, updateIndex, updateCollapse};
    },
    {
        persist: true
    }
);
